package com.yoomiito.app.widget.dialog

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.model.sdd.SddRights
import com.yoomiito.app.model.sdd.SddRightsTip
import com.yoomiito.app.utils.DensityUtil
import com.yoomiito.app.widget.SpacingDecoration

class SendMoreTipDialog(mContext:Context,val data: SddRights):BaseDialog(mContext, R.style.dialog_2){
    override fun setView(): View {
        val view = LayoutInflater.from(mContext).inflate(R.layout.dialog_send_more_tip,null,false)
        view.findViewById<ImageView>(R.id.close).setOnClickListener { dismiss() }
        view.findViewById<TextView>(R.id.know).setOnClickListener { dismiss() }
        view.findViewById<TextView>(R.id.dialogTitle).text = "${data.title}规则"
        val rcy = view.findViewById<androidx.recyclerview.widget.RecyclerView>(R.id.rcy)
        rcy.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
        rcy.addItemDecoration(SpacingDecoration(DensityUtil.dp2px(0f),DensityUtil.dp2px(16f),false))
        rcy.adapter = Adapter()
        setWidthPercent(0.72)
        if (data.tips.size>3){
            setmHeightPercent(0.47)
        }
        return view
    }

    inner class Adapter:BaseQuickAdapter<SddRightsTip,BaseViewHolder>(R.layout.item_rule,data.tips){
        override fun convert(helper: BaseViewHolder?, item: SddRightsTip?) {
            helper?.getView<TextView>(R.id.serialNum)?.text = helper?.layoutPosition?.plus(1).toString()
            helper?.getView<TextView>(R.id.rule)?.text = item?.title
            helper?.getView<TextView>(R.id.ruleCase)?.text = item?.example
        }
    }
}